package com.shuyun.hystrix.dynamic.config;

import com.shuyun.hystrix.dynamic.archaius.ConfigListener;

import java.util.*;

/**
 * @description: 暂时默认为配置中心配置管理类，提供参数获取与参数监听器等功能。
 * @author: shuai.chen@shuyun.com
 * @date: 2023/1/17 1:54 PM
 */
public class ConfigManager {

    /**
     * todo change tianji or mysql
     * 1. from callback entity_binding table.  需要组装 key
     *
     */
    private static Map<String, Object> dataMap = new HashMap<>();

    static {
        dataMap.put("hystrix.command.sjyj_shuyun.member.query.execution.isolation.thread.timeoutInMilliseconds", 0);
    }

    public static void setTimeoutInMilliseconds(String partner, String api, Object value){
        String key = "hystrix.command." + partner + "_" + api + ".execution.isolation.thread.timeoutInMilliseconds";
        dataMap.put(key, value);
    }

    public static Set<String> keys() {
        return dataMap.keySet();
    }

    public static Object get(String key) {
        return dataMap.get(key);
    }

    public static void addListener(ConfigListener configListener) {
        // xxx 绑定这个监听

        configListener.eventReceived(null, null);
    }

    public static String getString(String name, String defaultValue) {
        return null;
    }
}
